package com.lw.edu.controller;

import com.lw.commonutil.result.Result;
import com.lw.edu.entity.Chapter;
import com.lw.edu.entity.chapter.ChapterVo;
import com.lw.edu.service.ChapterService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/admin/edu/chapter")
public class ChapterController {
    @Autowired
    private ChapterService chapterService;
    //课程大纲列表,根据课程id查询
    @GetMapping("/getChapterVideo/{courseId}")
    public Result getChapterVideo(@PathVariable String courseId){
        List<ChapterVo> list= chapterService.getChapterVideoBycourseId(courseId);
        return Result.ok(list);
    }
    //添加章节
    @PostMapping("/addChapter")
    public Result addChapter(@RequestBody Chapter chapter){
        chapterService.save( chapter );
        return Result.ok();
    }
    //根据章节id查询
    @GetMapping("/getChapterInfo/{chapterId}")
    public Result getChapterInfo(@PathVariable String chapterId){
        Chapter chapter = chapterService.getById( chapterId );
        return Result.ok( chapter );
    }
    //修改章节
    @PostMapping("/updateChapter")
    public Result updateChapter(@RequestBody Chapter chapter){
        chapterService.updateById( chapter );
        return Result.ok();
    }
    //删除
    @DeleteMapping("/{chapterId}")
    public Result deleteChapter(@PathVariable String chapterId){
        //删除章节,如果里面有小节，不让删除
        boolean flag = chapterService.deleteChapter( chapterId );
        if (flag){
            return Result.ok();
        }else {
            return Result.fail();
        }
    }
}
